package interviewClassic150;

public class TwoSum {
    public int[] twoSum(int[] numbers, int target) {
        int[] res = new int[2];
        int left = 0;
        int right = numbers.length - 1;
        while (left < right) {
            int leftNum = numbers[left];
            int rightNum = numbers[right];
            if (leftNum + rightNum == target) {
                res[0] = left + 1;
                res[1] = right + 1;
                return res;
            } else if (leftNum + rightNum > target) {
                right--;
            } else {
                left++;
            }
        }

        return res;
    }
}
